﻿using KPIS.GERP.Models.Class;
using System;
using System.ServiceModel;
using KPIS.GERP.Models.Class;
using Resources;

// this is custom made of every wcf service used in GERP to override error communication when wcf client is try to disposing, instead of throw error, we just logging it and abort it.
// Remark: this is manual work

#region WCF Service Disposer

namespace KPIS.GERP.WEB.GIMS.IcmMasterService
{
	/// <summary>
	/// Icm Master Client
	/// </summary>
	public partial class IcmMasterServiceClient : IDisposable
	{ 
		#region IDisposable implementation

		/// <summary>
		/// IDisposable.Dispose implementation, calls Dispose(true).
		/// </summary>
		void IDisposable.Dispose()
		{
			Dispose(true);
		}

		/// <summary>
		/// Dispose worker method. Handles graceful shutdown of the
		/// client even if it is an faulted state.
		/// </summary>
		/// <param name="disposing">Are we disposing (alternative
		/// is to be finalizing)</param>
		protected virtual void Dispose(bool disposing)
		{
			if (!disposing) return;
			try
			{
				if (State != CommunicationState.Faulted)
				{
					Close();
				}
			}
			finally
			{
				if (State != CommunicationState.Closed)
				{
					Logger.Error(ErrorLocalization.ErrorWcfCommunicationStateIsFaultedWhenTringToDispose, null);
					Abort();
				}
			}
		}

		/// <summary>
		/// Finalizer.
		/// </summary>
		~IcmMasterServiceClient()
		{
			Dispose(false);
		}

		#endregion
	}
}

namespace KPIS.GERP.WEB.GIMS.EmployeeService
{
	public partial class EmployeeServiceClient : IDisposable
	{
		#region IDisposable implementation

		void IDisposable.Dispose()
		{
			Dispose(true);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (!disposing) return;
			try
			{
				if (State != CommunicationState.Faulted)
				{
					Close();
				}
			}
			finally
			{
				if (State != CommunicationState.Closed)
				{
					Logger.Error(ErrorLocalization.ErrorWcfCommunicationStateIsFaultedWhenTringToDispose + "[EmployeeServiceClient]");
					Abort();
				}
			}
		}

		~EmployeeServiceClient()
		{
			Dispose(false);
		}

		#endregion
	}
}

namespace KPIS.GERP.WEB.GIMS.JobsiteService
{
	public partial class JobsiteServiceClient : IDisposable
	{
		#region IDisposable implementation

		void IDisposable.Dispose()
		{
			Dispose(true);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (!disposing) return;
			try
			{
				if (State != CommunicationState.Faulted)
				{
					Close();
				}
			}
			finally
			{
				if (State != CommunicationState.Closed)
				{
					Logger.Error(ErrorLocalization.ErrorWcfCommunicationStateIsFaultedWhenTringToDispose + "[JobsiteServiceClient]");
					Abort();
				}
			}
		}

		~JobsiteServiceClient()
		{
			Dispose(false);
		}

		#endregion
	}
}

namespace KPIS.GERP.WEB.GIMS.MasBudgetSourceService
{
	public partial class MasBudgetSourceServiceClient : IDisposable
	{
		#region IDisposable implementation

		void IDisposable.Dispose()
		{
			Dispose(true);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (!disposing) return;
			try
			{
				if (State != CommunicationState.Faulted)
				{
					Close();
				}
			}
			finally
			{
				if (State != CommunicationState.Closed)
				{
					Logger.Error(ErrorLocalization.ErrorWcfCommunicationStateIsFaultedWhenTringToDispose + "[MasBudgetSourceServiceClient]");
					Abort();
				}
			}
		}

		~MasBudgetSourceServiceClient()
		{
			Dispose(false);
		}

		#endregion
	}
}

namespace KPIS.GERP.WEB.GIMS.MasLookUpService
{
	public partial class MasLookUpServiceClient : IDisposable
	{
		#region IDisposable implementation

		void IDisposable.Dispose()
		{
			Dispose(true);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (!disposing) return;
			try
			{
				if (State != CommunicationState.Faulted)
				{
					Close();
				}
			}
			finally
			{
				if (State != CommunicationState.Closed)
				{
					Logger.Error(ErrorLocalization.ErrorWcfCommunicationStateIsFaultedWhenTringToDispose + "[MasLookUpServiceClient]");
					Abort();
				}
			}
		}

		~MasLookUpServiceClient()
		{
			Dispose(false);
		}

		#endregion
	}
}

namespace KPIS.GERP.WEB.GIMS.MasLookUpTypeService
{
	public partial class MasLookUpTypeServiceClient : IDisposable
	{
		#region IDisposable implementation

		void IDisposable.Dispose()
		{
			Dispose(true);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (!disposing) return;
			try
			{
				if (State != CommunicationState.Faulted)
				{
					Close();
				}
			}
			finally
			{
				if (State != CommunicationState.Closed)
				{
					Logger.Error(ErrorLocalization.ErrorWcfCommunicationStateIsFaultedWhenTringToDispose + "[MasLookUpTypeServiceClient]");
					Abort();
				}
			}
		}

		~MasLookUpTypeServiceClient()
		{
			Dispose(false);
		}

		#endregion
	}
}

namespace KPIS.GERP.WEB.GIMS.MasResourceService
{
	public partial class MasResourceServiceClient : IDisposable
	{
		#region IDisposable implementation

		void IDisposable.Dispose()
		{
			Dispose(true);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (!disposing) return;
			try
			{
				if (State != CommunicationState.Faulted)
				{
					Close();
				}
			}
			finally
			{
				if (State != CommunicationState.Closed)
				{
					Logger.Error(ErrorLocalization.ErrorWcfCommunicationStateIsFaultedWhenTringToDispose + "[MasResourceServiceClient]");
					Abort();
				}
			}
		}

		~MasResourceServiceClient()
		{
			Dispose(false);
		}

		#endregion
	}
}

namespace KPIS.GERP.WEB.GIMS.MessageService
{
	public partial class MessageServiceClient : IDisposable
	{
		#region IDisposable implementation

		void IDisposable.Dispose()
		{
			Dispose(true);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (!disposing) return;
			try
			{
				if (State != CommunicationState.Faulted)
				{
					Close();
				}
			}
			finally
			{
				if (State != CommunicationState.Closed)
				{
					Logger.Error(ErrorLocalization.ErrorWcfCommunicationStateIsFaultedWhenTringToDispose + "[MessageServiceClient]");
					Abort();
				}
			}
		}

		~MessageServiceClient()
		{
			Dispose(false);
		}

		#endregion
	}
}

namespace KPIS.GERP.WEB.GIMS.MovementService
{
	public partial class MovementServiceClient : IDisposable
	{
		#region IDisposable implementation

		void IDisposable.Dispose()
		{
			Dispose(true);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (!disposing) return;
			try
			{
				if (State != CommunicationState.Faulted)
				{
					Close();
				}
			}
			finally
			{
				if (State != CommunicationState.Closed)
				{
					Logger.Error(ErrorLocalization.ErrorWcfCommunicationStateIsFaultedWhenTringToDispose + "[MovementServiceClient]");
					Abort();
				}
			}
		}

		~MovementServiceClient()
		{
			Dispose(false);
		}

		#endregion
	}
}

namespace KPIS.GERP.WEB.GIMS.ReceiveParcelService
{
	public partial class ReceiveParcelServiceClient : IDisposable
	{
		#region IDisposable implementation

		void IDisposable.Dispose()
		{
			Dispose(true);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (!disposing) return;
			try
			{
				if (State != CommunicationState.Faulted)
				{
					Close();
				}
			}
			finally
			{
				if (State != CommunicationState.Closed)
				{
					Logger.Error(ErrorLocalization.ErrorWcfCommunicationStateIsFaultedWhenTringToDispose + "[ReceiveParcelServiceClient]");
					Abort();
				}
			}
		}

		~ReceiveParcelServiceClient()
		{
			Dispose(false);
		}

		#endregion
	}
}

namespace KPIS.GERP.WEB.GIMS.RequestParcelService
{
	public partial class RequestParcelServiceClient : IDisposable
	{
		#region IDisposable implementation

		void IDisposable.Dispose()
		{
			Dispose(true);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (!disposing) return;
			try
			{
				if (State != CommunicationState.Faulted)
				{
					Close();
				}
			}
			finally
			{
				if (State != CommunicationState.Closed)
				{
					Logger.Error(ErrorLocalization.ErrorWcfCommunicationStateIsFaultedWhenTringToDispose + "[RequestParcelServiceClient]");
					Abort();
				}
			}
		}

		~RequestParcelServiceClient()
		{
			Dispose(false);
		}

		#endregion
	}
}

namespace KPIS.GERP.WEB.GIMS.WarehouseService
{
	public partial class WarehouseServiceClient : IDisposable
	{
		#region IDisposable implementation

		void IDisposable.Dispose()
		{
			Dispose(true);
		}

		protected virtual void Dispose(bool disposing)
		{
			if (!disposing) return;
			try
			{
				if (State != CommunicationState.Faulted)
				{
					Close();
				}
			}
			finally
			{
				if (State != CommunicationState.Closed)
				{
					Logger.Error(ErrorLocalization.ErrorWcfCommunicationStateIsFaultedWhenTringToDispose + "[WarehouseServiceClient]");
					Abort();
				}
			}
		}

		~WarehouseServiceClient()
		{
			Dispose(false);
		}

		#endregion
	}
}

// Remark not need to include SampleService, SampleService2, ServiceTest

#endregion